from pydantic import BaseModel, EmailStr, Field
from typing import Optional
from datetime import date, datetime

class PassengerBase(BaseModel):
    first_name: str = Field(..., min_length=1, max_length=50)
    last_name: str = Field(..., min_length=1, max_length=50)
    email: EmailStr
    phone: Optional[str] = Field(None, max_length=20)
    passport_number: Optional[str] = Field(None, max_length=20)
    date_of_birth: Optional[date] = None

class PassengerCreate(PassengerBase):
    pass

class PassengerUpdate(BaseModel):
    first_name: Optional[str] = Field(None, min_length=1, max_length=50)
    last_name: Optional[str] = Field(None, min_length=1, max_length=50)
    email: Optional[EmailStr] = None
    phone: Optional[str] = Field(None, max_length=20)
    passport_number: Optional[str] = Field(None, max_length=20)
    date_of_birth: Optional[date] = None

class PassengerResponse(PassengerBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True